from api.addEmpApi import addRmpApi
from common.assertTools import common_assert
from common.db_tools import DBTools
from common.header import get_header


class TestAddEmp(object):
    def setup_class(self):
        self.emp = addRmpApi()
        self.req_header = get_header()
    def setup(self):
        db=DBTools()
        db.db_iud("delete from bs_user where mobile='15145678905';")
    def teardown(self):  # 测试结束后,自动调用删除这个手机号
        DBTools.db_iud(f"delete from bs_user mobile='15145678905';")
    # def setup(self):  # 在每个普通方法执行前,自动调用(先删除数据库手机号)
    #     DBTools.db_iud(f"delete from bs_user where mobile='{TEL}';")
    # def teardown(self):  # 测试结束后,自动调用删除这个手机号
    #     DBTools.db_iud(f"delete from bs_user where mobile='{TEL}';")

    def test1_add_success(self):
        req_body = {"username": "张三", "mobile": "15145678905", "workNumber": "013"}
        resp=self.emp.add_emp(self.req_header,req_body)
        print("添加成功",resp.json())
        common_assert(resp, 200, True, 10000, "操作成功")

    def test2_mobile_null(self):
        req_body = {"username": "张三", "mobile": None, "workNumber": "013"}
        resp = self.emp.add_emp(self.req_header, req_body)
        print("手机号为空", resp.json())
        common_assert(resp, 200, False, 20002, "新增员工失败")
